home *** CD-ROM | disk | FTP | other *** search
- Path: news.bridge.net!news
- From: David Byrden <100101.2547@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: C++ OO question (long)
- Date: 28 Feb 1996 04:34:45 GMT
- Organization: self-employed
- Message-ID: <4h0m15$kps@news.bridge.net>
- References: <4h08uq$mve@madeline.INS.CWRU.Edu>
- NNTP-Posting-Host: ppp-mia4-144.bridge.net
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
-
-
- Bryan;
-
- When you define a copy ctor for a class, you usually need to define an
- assignment operator
-
- Matrix& operator=( const Matrix& other )
-
- as well. If not, the compiler generates a 'stupid' one and this is the
- cause of your crash.
-
- Your operator= should;
- Do nothing if its object is being assigned to itself
- Get rid of current data
- Make copy of 'other' data
- Return a reference to itself
-
-
- Also: when you declare with the assigment operator, the copy ctor is
- called. The new syntax is therefore preferred, though it means the same
- thing
-
- Matrix M3( M2 * M1 ) ;
-
-
- Also: I notice that your binary operators look like this;
-
-
- Matrix operator * (Matrix, Matrix);
-
-
- When you pass a Matrix by value, an ENTIRE MATRIX will be made using the
- copy ctor. This is not necessary. operator+ does not modify its
- argumenfs, so pass const references instead.
-
-
- David
-
-
-
-